// -*- C++ -*-
//===-- execution ---------------------------------------------------------===//
//
// Copyright (C) Intel Corporation
//
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// This file incorporates work covered by the following copyright and permission
// notice:
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
//
//===----------------------------------------------------------------------===//

#ifndef _ONEDPL_EXECUTION
#define _ONEDPL_EXECUTION

// Workarounds for libstdc++9, libstdc++10 when new TBB version is found in the environment
#if __cplusplus >= 201703L
#    if __has_include(<tbb/version.h>)
#        ifndef PSTL_USE_PARALLEL_POLICIES
#            define PSTL_USE_PARALLEL_POLICIES (_GLIBCXX_RELEASE != 9)
#        endif
#        ifndef _GLIBCXX_USE_TBB_PAR_BACKEND
#            define _GLIBCXX_USE_TBB_PAR_BACKEND (_GLIBCXX_RELEASE > 10)
#        endif
#    endif // __has_include(<tbb/version.h>)

// ATTENTION!!! Include the header from the C++ standard library before the oneDPL config header to see whether the _PSTL_VERSION macro is defined
#    if __has_include(<execution>)
#        include <execution>
#    endif // __has_include(<execution>)
#endif     // __cplusplus >= 201703L

#include "oneapi/dpl/pstl/onedpl_config.h"
#include "oneapi/dpl/pstl/execution_defs.h"

#define _ONEDPL_EXECUTION_POLICIES_DEFINED 1

#if _ONEDPL_ALGORITHM_FORWARD_DECLARED
#    include "oneapi/dpl/pstl/glue_algorithm_impl.h"

#    include "oneapi/dpl/internal/exclusive_scan_by_segment_impl.h"
#    include "oneapi/dpl/internal/inclusive_scan_by_segment_impl.h"
#    include "oneapi/dpl/internal/binary_search_impl.h"
#    include "oneapi/dpl/internal/reduce_by_segment_impl.h"
#endif

#if _ONEDPL_MEMORY_FORWARD_DECLARED
#    include "oneapi/dpl/pstl/glue_memory_impl.h"
#endif

#if _ONEDPL_NUMERIC_FORWARD_DECLARED
#    include "oneapi/dpl/pstl/glue_numeric_impl.h"
#endif

#if _ONEDPL_CPP17_EXECUTION_POLICIES_PRESENT
_PSTL_PRAGMA_MESSAGE_POLICIES(
    "The <Parallel STL> execution policies are defined in the namespace oneapi::dpl::execution")
#    include "oneapi/dpl/pstl/algorithm_impl.h"
#    include "oneapi/dpl/pstl/numeric_impl.h"
#    include "oneapi/dpl/pstl/parallel_backend.h"
#else
#    include "oneapi/dpl/pstl/glue_execution_defs.h"
_PSTL_PRAGMA_MESSAGE_POLICIES(
    "The <Parallel STL> execution policies are injected into the standard namespace std::execution")
#endif

namespace oneapi
{
namespace dpl
{
namespace execution
{
using namespace oneapi::dpl::execution;
} // end namespace execution
} // end namespace dpl
} // end namespace oneapi

namespace dpl = oneapi::dpl;

#endif /* _ONEDPL_EXECUTION */
